<?php 
class auto_message_api
{ 
	function auto_message_api_main($bot_id,$api_data_josn) 
	{ 
		global $mysql_conn,$v_file;
		$api_data_data = json_decode($api_data_josn);//转化上报数据从josn格式转化为数组
		$post_type = $api_data_data->{'post_type'};//截取消息类型
		if ($post_type == "receive_message") {
			$type = $api_data_data->{'type'};//获取发送的来源是好友还是群组
			$content = $api_data_data->{'content'};//获取发送的内容
			if ($type == "group_message"){
				$id = $api_data_data->{'group_id'};
				$send = "send_group_message";
				$name = $api_data_data->{'group'};
			} else if ($type == "friend_message") {
				$id = $api_data_data->{'sender_id'};
				$send = "send_friend_message";
				$name = $api_data_data->{'sender'};
			}
			$sql = "SELECT * from `auto_message` WHERE `auto_message_bot` = '".$bot_id."' and `auto_message_key` = '".$content."'";
			$result = mysql_query($sql,$mysql_conn);
			@$row=mysql_fetch_array($result);
			$auto_message_body = $row['auto_message_body'];
			$auto_message_use = $row['auto_message_use'];
			$auto_message_use_arr = explode(',',$auto_message_use); 
			if (!empty($auto_message_body)) {
				$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
				$result = mysql_query($sql,$mysql_conn);
				@$row=mysql_fetch_array($result);
				$bot_server_id = $row['bot_server_id'];
				$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
				$result = mysql_query($sql,$mysql_conn);
				@$row=mysql_fetch_array($result);
				$server_url = $row['server_url'];
				if (empty($auto_message_use)) {
					$url = $server_url."openwx/".$send."?id=".$id."&content=".urlencode($auto_message_body)."&client=".$bot_id; 
					$html = file_get_contents($url);
				} else if (in_array($name, $auto_message_use_arr)) {
					$url = $server_url."openwx/".$send."?id=".$id."&content=".urlencode($auto_message_body)."&client=".$bot_id; 
					$html = file_get_contents($url);
				}
			}
		}
	}
}

